{include file="header.html"}
<div id="main">
  {include file="menus.html"}
  <div id="rightCon" class="clearfix layui-body">
    <div class="scroller">
      <div class="search-form clearfix">
        <form method="get" id="formSearch">
          <div class="webkit-box box-align-center">
            <input type="hidden" name="r" value="manager/index" />
            {$lang.username}
            <input class="queryInput" type="text" name="username" value="{$smarty.get.username|escape}" />
            {$lang.phone_mob}
            <input class="queryInput" type="text" name="phone_mob" value="{$smarty.get.phone_mob|escape}" />
            <input type="submit" class="layui-btn layui-bg-blue layui-btn-sm block width7" value="{$lang.query}" />
            <!--{if $filtered}-->
            <a class="layui-btn layui-btn-primary layui-btn-sm box-align-center"
              href="{url route='manager/index'}">{$lang.cancel_query}</a>
            <!--{/if}-->
          </div>
        </form>
      </div>
      <div class="tablegrid">
        <table class="layui-hide" id="tablegrid" lay-filter="tablegrid"></table>
      </div>
      {include file="version.html"}
    </div>
  </div>
</div>
<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-bg-blue" lay-event="batdel"><i class="layui-icon layui-icon-close"></i>批量删除</button>
    <button class="layui-btn layui-btn-primary layui-border-black" lay-event="export"><i class="layui-icon layui-icon-export"></i>导出数据</button>
  </div>
</script>

<script type="text/html" id="colBar">
  <a class="ml5 mr5 blue pointer" lay-event="edit">编辑权限</a>
  <a class="ml5 mr5 blue pointer" lay-event="del" confirm="删除后将不能恢复，确认删除该项吗？">删除</a>
</script>
<script>
  layui.use('table', function () {
    var table = layui.table;

    table.render({
      elem: '#tablegrid'
      //,skin: 'line'
      , url: url(['manager/index', $("#formSearch").serializeJson()])
      , toolbar: '#toolbar'
      , defaultToolbar: ['filter', /*'exports',*/ 'print']
      , title: '管理员列表'
      //, size: 'lg'
      , cols: [[
        { type: 'checkbox', fixed: 'left' }
        , { field: 'userid', title: 'ID', width: 70, fixed: 'left', unresize: true, sort: true }
        , {
          field: 'username', title: '用户名', width: 200, templet: function (res) {
            return res.privs == 'all' ? res.username + '<span class="red f-13">(系统管理员)</span>' : res.username;
          }
        }
        , { field: 'phone_mob', title: '手机号码', width: 125, sort: true, align: 'center' }
        , { field: 'create_time', title: '注册时间', width: 175, sort: true }
        , { field: 'logins', title: '登录次数', width: 120, sort: true, align: 'center' }
        , { field: 'last_login', title: '上次登录时间', width: 180, sort: true, align: 'center' }
        , { field: 'last_ip', title: '上次登录IP', width: 180, align: 'center' }
        , { fixed: 'right', title: '操作', toolbar: '#colBar', width: 160, align: 'center' }
      ]]
      , page: {
        theme: 'blue'
      }
    });

    //监听头工具栏事件
    table.on('toolbar(tablegrid)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      if (checkStatus.data.length <= 0) {
        return false;
      }
      var items = new Array();
      $.each(checkStatus.data, function (i, item) {
        items.push(item.userid);
      });

      if (obj.event === 'batdel') {
        var btnObj = $('[lay-event="' + obj.event + '"]');
        btnObj.attr('confirm', '删除后将不能恢复，确认删除这 ' + items.length + ' 项吗？');
        ajaxRequest(btnObj, url(['manager/delete', { id: items.join(',') }]), function () {
          table.reload('tablegrid');
        });
      } else if (obj.event === 'export') {
        window.location.href = url(['manager/export', $.extend($("#formSearch").serializeJson(), { id: items.join(',') })]);
      }
    });

    //监听行工具事件
    table.on('tool(tablegrid)', function (obj) {
      var data = obj.data;
      if (obj.event === 'del') {
        var btnObj = $(obj.tr).find('[lay-event="' + obj.event + '"]');
        ajaxRequest(btnObj, url(['manager/delete', { id: data.userid }]), function () {
          obj.del();
        });
      } else if (obj.event === 'edit') {
        window.location.href = url(['manager/edit', { id: data.userid }]);
      }
    });
  });
</script>
{include file="footer.html"}